package dhz.storage.models;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoId;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

@Document(collection = "links")
public class ShareLink implements Serializable {
    // 这个链接的id，用来加速查询的，系统自动生成
    @MongoId
    private long id;
    // 被分享的文件在用户网盘的哪里
    private String path;
    // 分享的用户的用户名
    @Indexed
    private String identification;
    // 链接创建的时间
    @Indexed
    private Calendar creation;

    public ShareLink(){

    }

    public ShareLink(String user, String target){
        this.id = new Date().getTime()*1000 + new Random().nextInt()%1000;
        this.identification = user;
        this.path = target;
        this.creation = Calendar.getInstance();
        creation.add(Calendar.HOUR_OF_DAY, 8);
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getIdentification() {
        return identification;
    }

    public void setIdentification(String identification) {
        this.identification = identification;
    }

    public Calendar getCreation() {
        return creation;
    }

    public void setCreation(Calendar creation) {
        this.creation = creation;
    }
}
